var ns;
app = new Vue({
    el: '#app',
    data: {
        list: [],
        PublishType: 1,
        ID: 0,
        select_id: 0,
        select_name: ''
    },
    methods: {
        get_data: function() {
            var that = this;
            ns.post({
                keywords: that.keywords,
                action: 'getorgnizationlist',
            }, function(succeed, data, err) {
                if (succeed) {
                    if (data.list.length <= 0) {
                        return;
                    }
                    that.list = data.list;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        do_choose: function(item) {
            var that = this;
            for (var i = 0; i < that.list.length; i++) {
                var item1 = that.list[i];
                for (var j = 0; j < item1.children.length; j++) {
                    var item2 = item1.children[j];
                    if (item2.ID == item.ID) {
                        continue;
                    }
                    item2.isselected = false;
                }
            }
            item.isselected = !item.isselected;
            if (item.isselected) {
                that.select_id = item.ID;
                that.select_name = item.text;
            } else {
                that.select_id = 0;
                that.select_name = '';
            }
        },
        do_save: function(item) {
            var that = this;
            if (that.select_id > 0) {
                api.setPrefs({
                    key: 'choose_servicedepartmentid',
                    value: that.select_id
                });
            }
            if (that.select_name != '') {
                api.setPrefs({
                    key: 'choose_servicedepartmentname',
                    value: that.select_name
                });
            }
            if (that.select_id == 0) {
                api.toast({
                    msg: '请选择服务部门',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            setTimeout(function() {
                api.sendEvent({
                    name: 'do_choose_servicedepartment_complete'
                });
                api.closeWin({});
            }, 200)
            return;
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.ID = api.pageParam.id || 0;
    app.PublishType = api.pageParam.type || 0;
    app.get_data();
};
